package model;

/**
 * 用于包装登录的响应信息，以便转为JSON对象返回给前端
 */
public class Result {
    private Integer code;
    private String message;
    private Object data;

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }

    private Result() {}

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code) {
        this(code, null, null);
    }

    public Result(Integer code, Object data) {
        this(code, null, data);
    }

    public Result(Integer code, String message) {
        this(code, message, null);
    }

    public static Result fulfill() {
        return new Result(0);
    }

    public static Result fulfill(Object data) {
        return new Result(0, data);
    }

    public static Result reject(String message) {
        return new Result(10000, message);
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
